
/**
	 * Date: 08/11/2012
	 * 
	 * This class connect to the database and displays table.
	 * 
	 * author Kenneth Fagbe
	 * 
	 */

import java.sql.*;

public class ConnectDB {
static final String DB_URL = "jdbc:mysql://localhost:3306/Lindholmen";

//Create database credential for JDecider
 
static Connection conn= null;
static Statement stmt = null;
static String ankdamm;
static final String USER = "root";
static final String PASS = "";


public static void menu(){

try{
	//Register the JDBC driver
	Class.forName("com.mysql.jdbc.Driver");
	
	//open the connection
	System.out.println("Connect to database in Lindholmen");
	conn = DriverManager.getConnection(DB_URL, USER , PASS);
	
	System.out.println("Connected to a database successfully in Lindholmen");
	Statement s = conn.createStatement ();
	s.executeQuery ("SELECT * FROM food");
	ResultSet rs = s.getResultSet ();
	 while (rs.next ())
	   {
	       String idVal = rs.getString("FName");
	       String nameVal = rs.getString ("FType");
	       String catVal = rs.getString ("FPrice");
	       System.out.println (
	               "Dish Name : " + idVal
	               + ", Main Ingredient :  " + nameVal
	               + ", Price : " + catVal);
	   ankdamm +=  "Dish Name : " + idVal + ", Main Ingredient :  " + nameVal + ", Price : " + catVal + "\n";
	   }
	   
       GUI_Database.menu(ankdamm); 

	    
	   rs.close ();
	   s.close ();
}
catch(SQLException se){
	//Handle error for JDBC
	se.printStackTrace();
}catch (Exception e){
	e.printStackTrace();
}
}
}



